'''

https://time.geekbang.org/serv/v1/column/articles

https://res001.geekbang.org/media/audio/4c/ca/4c8f611e3e97e1a40a769685a22386ca/ld/ld.m3u8


ttps://res001.geekbang.org/media/audio/4c/ca/4c8f611e3e97e1a40a769685a22386ca/ld/ld-00002.ts

'''
import json
import re
import subprocess

headers = {
'Accept':'application/json, text/plain, */*',
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-TW;q=0.6',
'Connection':'keep-alive',
'Content-Length':'73',
'Content-Type':'application/json',
'Cookie':'_ga=GA1.2.922936372.1617166896; LF_ID=1617166896330-6169665-6008900; GCID=8a5a142-5d865b0-fc474f0-af5bacf; GRID=8a5a142-5d865b0-fc474f0-af5bacf; _gid=GA1.2.621688967.1627805871; GCESS=BgIE01gGYQ0BAQsCBgAMAQEEBAAvDQABCK2gJQAAAAAAAwTTWAZhBwQMjHjTCQEBBQQAAAAACgQAAAAABgQR5GBrCAED; gksskpitn=1f6e2e22-713e-4344-a3b0-722a7ec694d2; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%222465965%22%2C%22first_id%22%3A%2217886a88cfa818-00df0769652529-5771031-1327104-17886a88cfbacd%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E8%87%AA%E7%84%B6%E6%90%9C%E7%B4%A2%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC%22%2C%22%24latest_referrer%22%3A%22https%3A%2F%2Fwww.baidu.com%2Flink%22%2C%22%24latest_landing_page%22%3A%22https%3A%2F%2Ftime.geekbang.org%2F%22%7D%2C%22%24device_id%22%3A%2217886a88cfa818-00df0769652529-5771031-1327104-17886a88cfbacd%22%7D; Hm_lvt_022f847c4e3acd44d4a2481d9187f1e6=1627215097,1627805871,1627805908,1627821192; Hm_lvt_59c4ff31a9ee6263811b23eb921a5083=1627215097,1627805870,1627805908,1627821192; _gat=1; Hm_lpvt_022f847c4e3acd44d4a2481d9187f1e6=1627822062; Hm_lpvt_59c4ff31a9ee6263811b23eb921a5083=1627822062; gk_process_ev={%22count%22:18%2C%22target%22:%22%22}; SERVERID=1fa1f330efedec1559b3abbcb6e30f50|1627822062|1627821191',
'Host':'time.geekbang.org',
'Origin':'https://time.geekbang.org',
'Referer':'https://time.geekbang.org/column/intro/100017301',
'sec-ch-ua':'"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
'sec-ch-ua-mobile':'?0',
'Sec-Fetch-Dest':'empty',
'Sec-Fetch-Mode':'cors',
'Sec-Fetch-Site':'same-origin',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
}

data = {"cid":'126',"size":'100',"prev":'0',"order":"earliest","sample":'false',"chapter_ids":["346","347","348","349","350","344","351","352","353","1143"]}

import requests
# res = requests.post(url = 'https://time.geekbang.org/serv/v1/column/articles',data = json.dumps(data),headers=headers).json()
# # print(res)
# params = res.get('data')['list']
# # print(params)
# for i in params:
#     j = i.get('audio_url')
#
# res1 = requests.get('https://res001.geekbang.org/media/audio/4c/ca/4c8f611e3e97e1a40a769685a22386ca/ld/ld.m3u8')
# with open('sss.txt','w') as f:
#     f.write(res1.text)

#  视频下载
# with open('sss.txt','r') as f:
#     for i in f:
#         l = re.match('.*.ts',i)
#         if l == None:
#             continue
#         line = l.group()
#         url =  'https://res001.geekbang.org/media/audio/4c/ca/4c8f611e3e97e1a40a769685a22386ca/ld/ld.m3u8'
#         ts_url = url.replace('ld.m3u8', '') + line
#         res = requests.get(ts_url)
#         import os
#         if os.path.exists('video') == False:
#             os.mkdir('video')
#         with open('video/'+line,'wb')as f:
#             f.write(res.content)

#  合并视频
# import os
# ts_file = os.listdir(r'G:\TulingPaCong\day6\video')
# shell_file = '+'.join(ts_file)
#
# # print(shell_file)
#
# r'g:&&cd Tuling_PaCong\day6\video&&'
# l = fr'copy /b {shell_file} wyh.mp4'
# print(l)
# with open(r'G:\TulingPaCong\day6\video\wyh.bat','w') as f:
#     f.write(l)
import os
os.makedirs('feifei/fei')
os.mkdir('ffff')

